home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / morrison.zip / DIR.CB < prev    next >
Text File  |  1989-11-03  |  22KB  |  957 lines

  1. /* --------------------------------------------------------------------------- */
  2. /*                                                                                                  */
  3. /*                                     DIR Macro                                                 */
  4. /*                                                                                                  */
  5. /* --------------------------------------------------------------------------- */
  6. /*                                                                                                  */
  7. /*         This macro is designed to operate simular to the menus seen in      */
  8. /*         the popular NORTON COMMANDER program.    You can go UP or DOWN the     */
  9. /*         tree structure on the disk by moving the cursor over the proper     */
  10. /*         <DIR> entry in the directory and hitting the <Enter> key.             */
  11. /*                                                                                                  */
  12. /*         If the <Enter> key is hit and a file (instead of a directory         */
  13. /*         <DIR> entry) is highlighted then this file will be loaded into      */
  14. /*         BRIEF and be ready for editing.                                                 */
  15. /*                                                                                                  */
  16. /*         The <Ins> or <Space> key will TOGGLE the file marker for the         */
  17. /*         file that is currently highlighted.  <DIR> files MAY NOT BE          */
  18. /*         marked as they can not be edited.  After having marked one or         */
  19. /*         more (as many as you like) you can then have ALL of the MARKED      */
  20. /*         files loaded into BRIEF by hitting the <Alt-L> key.                     */
  21. /*                                                                                                  */
  22. /*         If you do NOT wish to edit any files, simply hit the <Esc> key      */
  23. /*         and you will be back editing the file that you started with.         */
  24. /*                                                                                                  */
  25. /*         The <Home>, <End>, <Up>, <Down>, <PgUp>, and <PgDn> keys are         */
  26. /*         used to move you around within the directory.                             */
  27. /*                                                                                                  */
  28. /*         Written BY:  Robert H. Morrison, 1 July 1988                              */
  29. /*                      Karlsruhe, West Germany                                             */
  30. /*                                                                                                  */
  31. /*         Last Update: 6 July 1988                                                         */
  32. /*                                                                                                  */
  33. /*                                                                                                  */
  34.  
  35. #define LINE      3
  36. #define SYSTEM       1
  37.  
  38. #define UP_DIR       ".."
  39. #define DOWN_DIR      ".\\"
  40.  
  41. #define SELECT       1
  42. #define UNSELECT 2
  43.  
  44. #define ALT_KEY      8
  45.  
  46. #include "dialog.h"
  47.  
  48. _init (...)
  49. {
  50.     int    mark_typ,
  51.             updir,
  52.             alt_done,
  53.             rows,
  54.             cols;
  55.  
  56.     string    new_file,
  57.                 bhelp,
  58.                 bdirfile,
  59.                 bdirpgm,
  60.                 bdiropt,
  61.                 bdirtxt,
  62.                 old_opt,
  63.                 select,
  64.                 unselect,
  65.                 alt_search,
  66.                 bdir;
  67.  
  68.     global    new_file,
  69.                 bhelp,
  70.                 bdirfile,
  71.                 bdirpgm,
  72.                 bdiropt,
  73.                 bdirtxt,
  74.                 old_opt,
  75.                 select,
  76.                 unselect,
  77.                 alt_search,
  78.                 alt_done,
  79.                 bdir,
  80.                 mark_typ,
  81.                 updir,
  82.                 rows,
  83.                 cols;
  84.  
  85.     alt_search = "\<■\|  ";
  86.     alt_done = FALSE;
  87.     bhelp = lower (inq_environment ("BHELP"));
  88.     if (bhelp != "")
  89.         bhelp += "\\";
  90.     bdiropt = "F";
  91.     bdirfile = bhelp + "temp.dir";
  92.     bdirpgm = bhelp + "bmakedir.exe";
  93.     bdirtxt = bhelp + "bmakedir.txt";
  94.     bdir = bdirpgm + ((" \-" + bdiropt) + (" \>&" + bdirfile));
  95.     inq_screen_size (rows, cols);
  96.     rows -= 10;
  97.     cols -= 42;
  98.     cols /= 2;
  99. }
  100.  
  101. dir (...)
  102. {
  103.     extern    to_bottom,
  104.                 display_file_name;
  105.  
  106.     int    dir_buffer,
  107.             old_buffer,
  108.             dir_window,
  109.             old_window,
  110.             end_line,
  111.             line;
  112.  
  113.     string    temp,
  114.                 this_line,
  115.                 current_dir,
  116.                 current_drive,
  117.                 answer;
  118.  
  119.     global    end_line,
  120.                 this_line,
  121.                 line,
  122.                 old_buffer,
  123.                 dir_buffer,
  124.                 current_dir,
  125.                 current_drive,
  126.                 answer;
  127.  
  128.     new_file = "";
  129.     message ("Reading disk directory...");
  130.     dos (bdir);
  131.     old_buffer = inq_buffer ();
  132.     dir_buffer = create_buffer ("DIR Ver 1.00", bdirtxt, SYSTEM);
  133.     create_window (cols, rows + 4, cols + 42, 3, "Ins - + Enter F1 F2 F4 F7 F8 F9 F10 Esc");
  134.     attach_buffer (dir_buffer);
  135.     set_buffer (dir_buffer);
  136.     getwd (NULL, current_dir);
  137.     current_dir = upper (current_dir);
  138.     current_drive = substr (current_dir, 1, 1);
  139.     top_of_buffer ();
  140.     read_file (bdirfile);
  141.     up ();
  142.     inq_position (end_line, NULL);
  143.     top_of_buffer ();
  144.  
  145.     keyboard_push ();
  146.     assign_to_key ("<Space>", "no_beep");
  147.     assign_to_key ("<Enter>", "select_dir");
  148.     assign_to_key ("<Home>", "top_of_dir");
  149.     assign_to_key ("<End>", "end_of_dir");
  150.     assign_to_key ("<Up>", "up_dir");
  151.     assign_to_key ("<Down>", "down_dir");
  152.     assign_to_key ("<PgUp>", "pgup_dir");
  153.     assign_to_key ("<PgDn>", "pgdown_dir");
  154.     assign_to_key ("<Ins>", "mark_dir");
  155.     assign_to_key ("<Ctrl-PgUp>", "up_1_dir");
  156.     assign_to_key ("<F1>", "help_dir");
  157.     assign_to_key ("<F2>", "change_drive");
  158.     assign_to_key ("<F4>", "load_marked");
  159.     assign_to_key ("<F7>", "make_dir");
  160.     assign_to_key ("<F8>", "delete_file");
  161.     assign_to_key ("<F9>", "set_mode");
  162.     assign_to_key ("<F10>", "_exit");
  163.     assign_to_key ("<Esc>", "_exit");
  164.     assign_to_key ("<Ctrl-\\>", "root_dir");
  165.     assign_to_key ("<\\>", "root_dir");
  166.     assign_to_key ("<Ctrl-R>", "read_dir");
  167.     assign_to_key ("<Keypad-minus>", "unselect_marks");
  168.     assign_to_key ("<Keypad-plus>", "select_marks");
  169.     assign_to_key ("<Alt-a>", "NC_alt_search a");
  170.     assign_to_key ("<Alt-b>", "NC_alt_search b");
  171.     assign_to_key ("<Alt-c>", "NC_alt_search c");
  172.     assign_to_key ("<Alt-d>", "NC_alt_search d");
  173.     assign_to_key ("<Alt-e>", "NC_alt_search e");
  174.     assign_to_key ("<Alt-f>", "NC_alt_search f");
  175.     assign_to_key ("<Alt-g>", "NC_alt_search g");
  176.     assign_to_key ("<Alt-h>", "NC_alt_search h");
  177.     assign_to_key ("<Alt-i>", "NC_alt_search i");
  178.     assign_to_key ("<Alt-j>", "NC_alt_search j");
  179.     assign_to_key ("<Alt-k>", "NC_alt_search k");
  180.     assign_to_key ("<Alt-l>", "NC_alt_search l");
  181.     assign_to_key ("<Alt-m>", "NC_alt_search m");
  182.     assign_to_key ("<Alt-n>", "NC_alt_search n");
  183.     assign_to_key ("<Alt-o>", "NC_alt_search o");
  184.     assign_to_key ("<Alt-p>", "NC_alt_search p");
  185.     assign_to_key ("<Alt-q>", "NC_alt_search q");
  186.     assign_to_key ("<Alt-r>", "NC_alt_search r");
  187.     assign_to_key ("<Alt-s>", "NC_alt_search s");
  188.     assign_to_key ("<Alt-t>", "NC_alt_search t");
  189.     assign_to_key ("<Alt-u>", "NC_alt_search u");
  190.     assign_to_key ("<Alt-v>", "NC_alt_search v");
  191.     assign_to_key ("<Alt-w>", "NC_alt_search w");
  192.     assign_to_key ("<Alt-x>", "NC_alt_search x");
  193.     assign_to_key ("<Alt-y>", "NC_alt_search y");
  194.     assign_to_key ("<Alt-z>", "NC_alt_search z");
  195.     assign_to_key ("<Alt-_>", "NC_alt_search _");
  196.     assign_to_key ("<Alt-0>", "NC_alt_search 0");
  197.     assign_to_key ("<Alt-1>", "NC_alt_search 1");
  198.     assign_to_key ("<Alt-2>", "NC_alt_search 2");
  199.     assign_to_key ("<Alt-3>", "NC_alt_search 3");
  200.     assign_to_key ("<Alt-4>", "NC_alt_search 4");
  201.     assign_to_key ("<Alt-5>", "NC_alt_search 5");
  202.     assign_to_key ("<Alt-6>", "NC_alt_search 6");
  203.     assign_to_key ("<Alt-7>", "NC_alt_search 7");
  204.     assign_to_key ("<Alt-8>", "NC_alt_search 8");
  205.     assign_to_key ("<Alt-9>", "NC_alt_search 9");
  206.  
  207.     drop_anchor (LINE);
  208.     message ("%s", current_dir);
  209.     refresh ();
  210.  
  211.     process ();
  212.  
  213.     keyboard_pop ();
  214.     delete_window ();
  215.     if (new_file != "")
  216.         {
  217.         if (new_file != "Load Multiple Files")
  218.             {
  219.             message ("Loading \"%s\" for editing...", new_file);
  220.             edit_file (new_file);
  221.             old_buffer = inq_buffer ();
  222.             }
  223.         else
  224.             {
  225.             top_of_buffer ();
  226.             while (search_fwd ("<\\c■"))
  227.                 {
  228.                 this_line = read ();
  229.                 down ();
  230.                 new_file = trim (substr (this_line, 3, 8));
  231.                 new_file += "." + trim (substr (this_line, 12, 3));
  232.                 message ("Loading \"%s\" for editing...", new_file);
  233.                 edit_file (new_file);
  234.                 old_buffer = inq_buffer ();
  235.                 set_buffer (dir_buffer);
  236.                 }
  237.             }
  238.         }
  239.     set_buffer (old_buffer);
  240.     delete_buffer (dir_buffer);
  241.     display_file_name ();
  242. }
  243.  
  244. no_beep (...)
  245. {
  246.     return;
  247. }
  248.  
  249. end_NC_alt (...)
  250. {
  251.     get_parm (0, alt_search);
  252.     exit ();
  253. }
  254.  
  255. NC_alt_search (...)
  256. {
  257.     extern    _do_beep;
  258.  
  259.     int    alt_line;
  260.  
  261.     string    alt_char;
  262.  
  263.     keyboard_push ();
  264.     assign_to_key ("<Enter>", "end_NC_alt <Enter>");
  265.     assign_to_key ("<Home>", "end_NC_alt <Home>");
  266.     assign_to_key ("<End>", "end_NC_alt <End>");
  267.     assign_to_key ("<Up>", "end_NC_alt <Up>");
  268.     assign_to_key ("<Down>", "end_NC_alt <Down>");
  269.     assign_to_key ("<PgUp>", "end_NC_alt <PgUp>");
  270.     assign_to_key ("<PgDn>", "end_NC_alt <PgDn>");
  271.     assign_to_key ("<Ins>", "end_NC_alt <Ins>");
  272.     assign_to_key ("<Ctrl-PgUp>", "end_NC_alt <Ctrl-PgUp>");
  273.     assign_to_key ("<F1>", "end_NC_alt <F1>");
  274.     assign_to_key ("<F2>", "end_NC_alt <F2>");
  275.     assign_to_key ("<F4>", "end_NC_alt <F4>");
  276.     assign_to_key ("<F7>", "end_NC_alt <F7>");
  277.     assign_to_key ("<F8>", "end_NC_alt <F8>");
  278.